package controller;

import dao.PhoneDao;
import dao.impl.PhoneDaoImpl;
import entity.Phone;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * 登录成功后才进入这个后端
 */
@WebServlet("/findAllPhone.do")
public class FindAllPetsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PhoneDao phoneDao = new PhoneDaoImpl();

        try {
            //执行查询，将集合存到request,并将集合重命名为phone
            req.setAttribute("phone",phoneDao.selectAllPhone());

            /**
             * 跳转到主界面
             */
            req.getRequestDispatcher("/phone.jsp").forward(req,resp);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
